package com.demo.SocketServer;

import java.io.IOException;
import java.net.Inet4Address;
import java.net.InetAddress;
import java.net.NetworkInterface;
import java.net.SocketException;
import java.util.Enumeration;

import com.demo.SocketServer.bio.BIOSocketServer;

public class MainStarter {

	public static void main(String[] args) throws IOException {
		getLoaclIP();
		ISocketServer server = new BIOSocketServer();
		server.start();
	}

	public static void getLoaclIP() throws SocketException {
		Enumeration<NetworkInterface> allNetInterfaces = NetworkInterface.getNetworkInterfaces();
		System.out.print("本机的IP:");
		while (allNetInterfaces.hasMoreElements()) {
			NetworkInterface netInterface = (NetworkInterface) allNetInterfaces
					.nextElement();
			Enumeration<InetAddress> addresses = netInterface.getInetAddresses();
			while (addresses.hasMoreElements()) {
				InetAddress ip = addresses.nextElement();
				if (ip != null && ip instanceof Inet4Address) {
					System.out.print(ip.getHostAddress()+",");
				}
			}
		}
		System.out.println();
	}

}
